package com.itboy.mall.pms.productattrvalue.controller;

import java.util.List;
import java.util.Arrays;

import com.itboy.mall.pms.productattrvalue.domain.MallProductAttrValue;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.itboy.common.annotation.RepeatSubmit;
import com.itboy.common.annotation.Log;
import com.itboy.common.core.controller.BaseController;
import com.itboy.common.core.domain.AjaxResult;
import com.itboy.common.enums.BusinessType;
import com.itboy.mall.pms.productattrvalue.vo.MallProductAttrValueVo;
import com.itboy.mall.pms.productattrvalue.bo.MallProductAttrValueQueryBo;
import com.itboy.mall.pms.productattrvalue.bo.MallProductAttrValueAddBo;
import com.itboy.mall.pms.productattrvalue.bo.MallProductAttrValueEditBo;
import com.itboy.mall.pms.productattrvalue.service.IMallProductAttrValueService;
import com.itboy.common.utils.poi.ExcelUtil;
import com.itboy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * spu属性值Controller
 *
 * @author itboy
 * @date 2021-08-07
 */
@Validated
@Api(value = "spu属性值控制器", tags = {"spu属性值管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/mall/productAttrValue")
public class MallProductAttrValueController extends BaseController {

    private final IMallProductAttrValueService iMallProductAttrValueService;

    /**
     * 查询spu属性值列表
     */
    @ApiOperation("查询spu属性值列表")
    @PreAuthorize("@ss.hasPermi('mall:productAttrValue:list')")
    @GetMapping("/list")
    public TableDataInfo<MallProductAttrValueVo> list(@Validated MallProductAttrValueQueryBo bo) {
        return iMallProductAttrValueService.queryPageList(bo);
    }


	/**
	 * 按照spuId查询
	 */
	@ApiOperation("按照spuId查询")
	@GetMapping("/getListBySpuId/{spuId}")
	public AjaxResult<List<MallProductAttrValue>> getListBySpuId(@NotNull(message = "spuId不能为空")
													  @PathVariable("spuId") Long spuId) {
		return AjaxResult.success(iMallProductAttrValueService.getListBySpuId(spuId));
	}

    /**
     * 导出spu属性值列表
     */
    @ApiOperation("导出spu属性值列表")
    @PreAuthorize("@ss.hasPermi('mall:productAttrValue:export')")
    @Log(title = "spu属性值", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<MallProductAttrValueVo> export(@Validated MallProductAttrValueQueryBo bo) {
        List<MallProductAttrValueVo> list = iMallProductAttrValueService.queryList(bo);
        ExcelUtil<MallProductAttrValueVo> util = new ExcelUtil<MallProductAttrValueVo>(MallProductAttrValueVo.class);
        return util.exportExcel(list, "spu属性值");
    }

    /**
     * 获取spu属性值详细信息
     */
    @ApiOperation("获取spu属性值详细信息")
    @PreAuthorize("@ss.hasPermi('mall:productAttrValue:query')")
    @GetMapping("/{id}")
    public AjaxResult<MallProductAttrValueVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iMallProductAttrValueService.queryById(id));
    }

    /**
     * 新增spu属性值
     */
    @ApiOperation("新增spu属性值")
    @PreAuthorize("@ss.hasPermi('mall:productAttrValue:add')")
    @Log(title = "spu属性值", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody MallProductAttrValueAddBo bo) {
        return toAjax(iMallProductAttrValueService.insertByAddBo(bo) ? 1 : 0);
    }


	/**
	 * 新增spu属性值
	 */
	@ApiOperation("修改spu属性值")
	@PreAuthorize("@ss.hasPermi('mall:productAttrValue:add')")
	@Log(title = "修改spu属性值", businessType = BusinessType.INSERT)
	@RepeatSubmit
	@PostMapping("/updateBatch/{spuId}")
	public AjaxResult<Void> addBatch(@NotNull(message = "spuId不能为空")
									 @PathVariable("spuId")Long spuId,@Validated @RequestBody List<MallProductAttrValue> bo) {
		return toAjax(iMallProductAttrValueService.updateBatch(spuId,bo) ? 1 : 0);
	}

    /**
     * 修改spu属性值
     */
    @ApiOperation("修改spu属性值")
    @PreAuthorize("@ss.hasPermi('mall:productAttrValue:edit')")
    @Log(title = "修改spu属性值", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody MallProductAttrValueEditBo bo) {
        return toAjax(iMallProductAttrValueService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除spu属性值
     */
    @ApiOperation("删除spu属性值")
    @PreAuthorize("@ss.hasPermi('mall:productAttrValue:remove')")
    @Log(title = "spu属性值" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iMallProductAttrValueService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
